package com.ruoyi.dynamic.controller.crm;


import com.ruoyi.common.core.annotation.valid.group.ValidGroup;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.dynamic.model.pojo.entity.Gift;
import com.ruoyi.dynamic.model.pojo.request.app.AppGiftSearchRequest;
import com.ruoyi.dynamic.model.pojo.request.crm.CrmGiftAddOrEditRequest;
import com.ruoyi.dynamic.service.IGiftService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "CRM-礼物相关", description = "CRM-礼物相关")
@RestController
@RequestMapping(PathConstant.CRM_PATH + "gift")
public class CrmGiftController {

    @Autowired
    private IGiftService iGiftService;


    @RequiresPermissions("dynamic:gift:list")
    @Operation(summary = "礼物列表", description = "礼物列表")
    @GetMapping("listPage")
    public R listPage(@ParameterObject AppGiftSearchRequest request) {
        Pages<Gift> pages = iGiftService.listPage(request, 0L);
        return R.ok(pages);
    }

    @RequiresPermissions("dynamic:gift:addOrEdit")
    @Operation(summary = "添加编辑礼物", description = "添加编辑礼物")
    @PostMapping("addOrEdit")
    public R addOrEdit(@RequestBody @Validated({ValidGroup.Update.class, ValidGroup.Insert.class}) CrmGiftAddOrEditRequest request) {
        return R.ok(iGiftService.addOrEdit(request));
    }

    @RequiresPermissions("dynamic:gift:remove")
    @Operation(summary = "删除礼物", description = "删除礼物")
    @DeleteMapping("del")
    public R del(Long id) {
        return R.ok(iGiftService.removeById(id));
    }


    @Operation(summary = "详情", description = "详情")
    @GetMapping("/{id}")
    public R info(@PathVariable("id") Long id) {
        return R.ok(iGiftService.getById(id));
    }

}

